#ifndef SESSIONMANAGER_H
#define SESSIONMANAGER_H

#include <QObject>
#include <QString>

class SessionManager : public QObject {
    Q_OBJECT

    static QString userID;
    static QString userName;

public:
    static void setUserID(const QString &id) { userID = id; }
    static QString getUserID() { return userID; }

    static SessionManager& instance() {
        static SessionManager instance;
        return instance;
    }

    bool isLoggedIn() const { return loggedIn; }
    void setLoggedIn(bool status) {
        if (loggedIn != status) {
            loggedIn = status;
            emit loginStatusChanged(loggedIn);
        }
    }

    static void setIsLogin(bool status);
    static bool getIsLogin();

    static void setUsername(const QString& userN) { userName = userN; }
    static QString getUsername()  { return userName; }


signals:
    void loginStatusChanged(bool loggedIn);

private:
    bool loggedIn = false;
    static bool isLogin;

    // 禁用拷贝构造函数和赋值运算符，确保单例
    SessionManager() {}
    SessionManager(const SessionManager&) = delete;
    SessionManager& operator=(const SessionManager&) = delete;
};

#endif // SESSIONMANAGER_H
